package p3;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-11-15
 * Time: 10:24
 */

public class Main2 {
    public static void main(String[] args) {
//       series();
       myThread();
    }
    public static void series(){
        long begin = System.currentTimeMillis();
        int a=1,b=1;
        for(long i=0;i<10_0000_0000;i++) {
            a++;
        }
        for(long i=0;i<10_0000_0000;i++) {
            b++;
        }
        long end = System.currentTimeMillis();
        System.out.println(end-begin);
    }
//    public static void  series() {
//        int a=1;
//        int b=1;
//        long begin = System.currentTimeMillis();
//        for(long i=0;i<10_0000_0000;i++) {
//            a++;
//        }
//        for(long i=0;i<10_0000_0000;i++) {
//            b++;
//        }
//        //currentTimeMillis 用来统计时间戳  结束时间
//        long end = System.currentTimeMillis();
//        System.out.println("运行时间:" + (end-begin));
//    }
    public static void myThread(){
        long begin = System.currentTimeMillis();
        Thread t1 = new Thread(new Runnable() {
            int a=0;
            @Override
            public void run() {
                while(a<=10_0000_0000){
                    a++;
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {

            int a=0,b=0;
            @Override
            public void run() {
                int b=0;
                while(b<=10_0000_0000){
                    b++;
                }
            }
        });
        t1.start();
        t2.start();

        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        long end = System.currentTimeMillis();
        System.out.println(end-begin);
    }

}
